#ifndef _ITEM_HEADER
#define _ITEM_HEADER

#include <string>
#include <ctime>
#include <cassert>


#define ID_SIZE		20


class Item{
	char* _id;
	void initId();
public:
	Item()
	{
		// _id = newId(); // Error C2440: '=' : cannot convert from 'const char *' to 'char [20]'
		// strcpy(_id, newId());
		initId();
	}
	virtual ~Item()
	{
		// free(_id);
		delete[] _id;
	}

	const char* getId() const
	{
		assert(_id != NULL);
		return _id;
	}

	virtual void info() const{}
};

void Item::initId()
{	
	_id = (char*)malloc(sizeof(char) * ID_SIZE);	
	memset(_id, '\0', ID_SIZE); // The third parameter should be not bigger than the size malloced
	time_t rawtime;
	struct tm* ptm;
	time(&rawtime);
	// ptm = gmtime(&rawtime);
	ptm = localtime(&rawtime);		
	srand(rawtime + rand());		
	sprintf(_id, "%4d%2.2d%2.2d%2.2d%2.2d%2.2d%5.5d", ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, rand());
}
#endif // _ITEM_HEADER